import {
    MemberDetail
} from './member-detail.model'
const memberDetail = new MemberDetail()
Page({
    data: {
        memberList: [],
        page: 1
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
        let that = this
        that._loadData()
    },

    /**
     * 获取所有数据
     */
    _loadData() {
        let that = this
        that.getMemberDetailData()
    },

    /**
     * 获取积分明细
     */
    getMemberDetailData() {
        let that = this
        memberDetail.getMemberDetailData().then((res) => {
            that.setData({
                memberList: res.data
            })
        }).then(() => {
            wx.stopPullDownRefresh()
            wx.hideNavigationBarLoading()
            wx.hideLoading()
        })
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
        wx.showLoading({
            title: '正在加载数据',
        })
        let that = this
        wx.showNavigationBarLoading()
        that._loadData()
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        wx.showLoading({
            title: '正在加载数据',
        })
        let that = this,
            param = {
                page: that.data.page + 1
            }
        that.setData(param)
        memberDetail.getMemberDetailData(param).then((res) => {
            let result = that.data.memberList
            result = result.concat(res.data)
            that.setData({
                memberList: result
            })
        }).then(() => {
            wx.hideLoading()
        })
    }
})